package com.fla.millioner.ui.support;

import java.text.NumberFormat;
import java.util.Locale;

import com.alone1672.millioner.R;
import com.fla.millioner.MillionerApplication;

import android.content.Context;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;
public class LevelsAdapter extends ArrayAdapter<Integer> {
    private static final NumberFormat FORMATTER = NumberFormat.getIntegerInstance(new Locale("RU"));

    private int level = 1;

    public LevelsAdapter(Context context) {
        super(context, R.layout.level_row, MillionerApplication.LEVELS_DATA);
    }

    public void updateLevel(int level) {
        this.level = level;
        notifyDataSetChanged();
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        TextView view = (TextView) LayoutInflater.from(parent.getContext()).inflate(R.layout.level_row, null);

        view.setText(FORMATTER.format(MillionerApplication.LEVELS_DATA[position]));

        view.setBackgroundColor(14 - position < level ? Color.argb(100, 0, 255, 0) : Color.TRANSPARENT);
        view.setTextColor((15 - position) % 5 == 0 ? Color.YELLOW : Color.WHITE);

        return view;
    }

    @Override
    public boolean isEnabled(int position) {
        return false;
    }
}
